Shader "FormeWork/Brush" {
    Properties{
        _MainTex("_MainTex", 2D) = "white" {}
        _BrushPos("BrushPos", Vector) = (0, 0, 0, 0)
        _BrushColor("BrushColor", Color) = (1, 1, 1, 1)
        _BrushSize("BrushSize", float) = 0.01
        _XYScaling("XYScaling", float) = 1
    }
        SubShader{
            Pass {
                CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                #include "UnityCG.cginc"

                struct appdata {
                    float4 vertex : POSITION;
                    float2 uv : TEXCOORD0;
                };

                struct v2f {
                    float2 uv : TEXCOORD0;
                    float4 vertex : SV_POSITION;
                };

                sampler2D _MainTex;

                float4 _BrushPos;
                float4 _BrushColor;
                float _BrushSize;
                float _XYScaling;

                v2f vert(appdata v) {
                    v2f o;
                    o.vertex = UnityObjectToClipPos(v.vertex);
                    o.uv = v.uv;
                    return o;
                }

                fixed4 frag(v2f i) : SV_Target {
                    fixed4 col = tex2D(_MainTex, i.uv);
                    
                    float2 uv = i.uv;
                    uv.x = uv.x * _XYScaling;
                    _BrushPos.x = _BrushPos.x * _XYScaling;
                    if (length(uv - _BrushPos.xy) < _BrushSize)
                    {
                        col = _BrushColor * _BrushColor.w + col * (1 - _BrushColor.w);
                    }
                    return col;
                }
                ENDCG
            }
    }
}
